package com.zsc.wxm.ysh.anjo.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 分页工具类
 * @author playmaker
 * @since 2021/1/11
 */
@Data
@NoArgsConstructor
public class PageUtil {
    /**
     * 总记录
     */
    private Integer total;

    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 当前页
     */
    private Integer currPage;

    /**
     * 每页的记录数
     */
    private Integer pageSize;

    /**
     * 列表数据
     */
    private List<?> list;

    public PageUtil(List<?> list,int total,int currPage,int pageSize){
        this.list = list;
        this.total = total;
        this.pageSize = pageSize;
        this.currPage = currPage;
        this.total = (int)Math.ceil((double) total / pageSize);
    }

    /**
     * 分页
     */
    public PageUtil(IPage<?> page){
        this.list = page.getRecords();
        this.total = (int)page.getTotal();
        this.pageSize = (int)page.getSize();
        this.pageSize = (int)page.getSize();
        this.totalPage = (int)page.getPages();
    }
}
